import {
  createRouter,
  createWebHashHistory
} from 'vue-router'

const routes = [{
    path: '/',
    name: 'home',
    component: () => import('../views/home/index.vue'),
    meta: {
      title: "首页"
    }
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login/index.vue'),
    meta: {
      title: "登录"
    }
  },
  {
    path: '/register',
    name: 'register',
    component: () => import('../views/login/register.vue'),
    meta: {
      title: "注册"
    }
  },
  {
    path: '/forget',
    name: 'forget',
    component: () => import('../views/login/forget.vue'),
    meta: {
      title: "忘记密码"
    }
  },
  {
    path: '/notice',
    name: 'notice',
    component: () => import('../views/home/notice.vue'),
    meta: {
      title: "公告"
    }
  },
  {
    path: '/noticeDetails',
    name: 'noticeDetails',
    component: () => import('../views/home/noticeDetails.vue'),
    meta: {
      title: "公告详情"
    }
  },
  {
    path: '/goodsDetails',
    name: 'goodsDetails',
    component: () => import('../views/home/goodsDetails.vue'),
    meta: {
      title: "商品详情"
    }
  },
  {
    path: '/submitOrders',
    name: 'submitOrders',
    component: () => import('../views/home/submitOrders.vue'),
    meta: {
      title: "提交订单"
    }
  },
  {
    path: '/paySuccess',
    name: 'paySuccess',
    component: () => import('../views/home/paySuccess.vue'),
    meta: {
      title: "支付成功"
    }
  },
  {
    path: '/classify',
    name: 'classify',
    component: () => import('../views/classify/index.vue'),
    meta: {
      title: "商品分类"
    }
  },
  {
    path: '/business',
    name: 'business',
    component: () => import('../views/business/index.vue'),
    meta: {
      title: "商学院"
    }
  },
  {
    path: '/businessDetails',
    name: 'businessDetails',
    component: () => import('../views/business/businessDetails.vue'),
    meta: {
      title: "视频详情"
    }
  },
  {
    path: '/cart',
    name: 'cart',
    component: () => import('../views/cart/index.vue'),
    meta: {
      title: "购物车"
    }
  },
  {
    path: '/my',
    name: 'my',
    component: () => import('../views/my/index.vue'),
    meta: {
      title: "个人中心"
    }
  },
  {
    path: '/integral',
    name: 'integral',
    component: () => import('../views/my/integral.vue'),
    meta: {
      title: "积分"
    }
  },
  {
    path: '/integralExchange',
    name: 'integralExchange',
    component: () => import('../views/my/integralExchange.vue'),
    meta: {
      title: "积分兑换"
    }
  },
  {
    path: '/interRecord',
    name: 'interRecord',
    component: () => import('../views/my/interRecord.vue'),
    meta: {
      title: "兑换记录"
    }
  },
  {
    path: '/shareOutBonus',
    name: 'shareOutBonus',
    component: () => import('../views/my/shareOutBonus.vue'),
    meta: {
      title: "持票分红"
    }
  },
  {
    path: '/uploadRecord',
    name: 'uploadRecord',
    component: () => import('../views/my/uploadRecord.vue'),
    meta: {
      title: "上传记录"
    }
  },
  {
    path: '/upload',
    name: 'upload',
    component: () => import('../views/my/upload.vue'),
    meta: {
      title: "凭证上传"
    }
  },
  {
    path: '/safe',
    name: 'safe',
    component: () => import('../views/my/safe.vue'),
    meta: {
      title: "安全仓"
    }
  },
  {
    path: '/order',
    name: 'order',
    component: () => import('../views/my/order.vue'),
    meta: {
      title: "我的订单"
    }
  },
  {
    path: '/orderDetails',
    name: 'orderDetails',
    component: () => import('../views/my/orderDetails.vue'),
    meta: {
      title: "订单详情"
    }
  },
  {
    path: '/logistics',
    name: 'logistics',
    component: () => import('../views/my/logistics.vue'),
    meta: {
      title: "物流信息"
    }
  },
  {
    path: '/setting',
    name: 'setting',
    component: () => import('../views/my/setting.vue'),
    meta: {
      title: "个人设置"
    }
  },
  {
    path: '/info',
    name: 'info',
    component: () => import('../views/my/info.vue'),
    meta: {
      title: "个人信息"
    }
  },
  {
    path: '/changePass',
    name: 'changePass',
    component: () => import('../views/my/changePass.vue'),
    meta: {
      title: "修改登录密码"
    }
  },
  {
    path: '/team',
    name: 'team',
    component: () => import('../views/my/team.vue'),
    meta: {
      title: "我的团队"
    }
  },
  {
    path: '/myAddr',
    name: 'myAddr',
    component: () => import('../views/my/myAddr.vue'),
    meta: {
      title: "我的地址"
    }
  },
  {
    path: '/addAddr',
    name: 'addAddr',
    component: () => import('../views/my/addAddr.vue'),
    meta: {
      title: "添加收货地址"
    }
  },
  {
    path: '/share',
    name: 'share',
    component: () => import('../views/my/share.vue'),
    meta: {
      title: "邀请好友"
    }
  },
  {
    path: '/regionalMap',
    name: 'regionalMap',
    component: () => import('../views/my/regionalMap.vue'),
    meta: {
      title: "区域地图"
    }
  },
]

const router = createRouter({
  // history: 引入 createWebHistory hash: 引入 createWebHashHistory 
  history: createWebHashHistory(process.env.BASE_URL),
  routes
})

//导航守卫
// 使用 router.beforeEach 注册一个全局前置守卫，判断用户是否登陆
// 不重定向白名单
// const whiteList = ['login', 'forget', 'register']
router.beforeEach((to, from, next) => {
  //设置每页title
  if (to.meta.title) {
    document.title = to.meta.title
    next()
  }

  // if (whiteList.indexOf(to.name) !== -1) {
  //   next();
  // } else {
  //   if (localStorage.getItem('token')) {
  //     next()
  //   } else {
  //     //errorShow('token失效，请重新登录')
  //     next(`/login`) // 否则全部重定向到登录页
  //   }
  // }

});

export default router